<template>
  <a-modal v-model="show" title="上传录音文件" @cancel="onClose" :width="800">
    <template slot="footer">
      <a-button key="back" @click="onClose">
        取消
      </a-button>
<!--      <a-button key="submit" type="primary" :loading="loading" @click="handleSubmit">-->
<!--        提交-->
<!--      </a-button>-->
    </template>
    <a-upload-dragger
      name="file"
      :multiple="false"
      :customRequest="customRequest">
      <p class="ant-upload-drag-icon">
        <a-icon type="inbox" />
      </p>
      <p class="ant-upload-text">
        单击或将文件拖到此区域进行上传
      </p>
      <p class="ant-upload-hint">
        Support for a single or bulk upload. Strictly prohibit from uploading company data or other
        band files
      </p>
    </a-upload-dragger>
  </a-modal>
</template>

<script>
import {mapState} from 'vuex'
import moment from 'moment'
moment.locale('zh-cn')
const formItemLayout = {
  labelCol: { span: 24 },
  wrapperCol: { span: 24 }
}
export default {
  name: 'recordAdd',
  props: {
    recordAddVisiable: {
      default: false
    }
  },
  computed: {
    ...mapState({
      currentUser: state => state.account.user
    }),
    show: {
      get: function () {
        return this.recordAddVisiable
      },
      set: function () {
      }
    }
  },
  data () {
    return {
      formItemLayout,
      form: this.$form.createForm(this),
      loading: false
    }
  },
  mounted () {
  },
  methods: {
    customRequest (file) {
      const formData = new FormData()
      formData.append('file', file.file)
      this.$upload('/cos/minio/voice/upload/oss', formData).then((r) => {
        this.$message.success(`${file.file.name} 文件上传成功,正在解析中...`)
        this.onClose()
      }).catch((r) => {
        console.error(r)
        this.$message.error(`${file.file.name} 文件上传失败.`)
      })
    },
    handleChange (info) {
      const status = info.file.status
      if (status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (status === 'done') {
        this.$message.success(`${info.file.name} 文件上传成功,正在解析中...`)
        this.onClose()
      } else if (status === 'error') {
        this.$message.error(`${info.file.name} 文件上传失败.`)
      }
    },
    onClose () {
      this.$emit('close')
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
        values.content = this.editor.getHtml()
        if (!err) {
          this.loading = true
          this.$post('/cos/record-info', {
            ...values
          }).then((r) => {
            this.reset()
            this.$emit('success')
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
<style scoped>

</style>
